package com.tfy.liquor.dao;

import com.tfy.liquor.bean.UserPurse;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

@Mapper
@Service
public interface UserPurseDao {
    // 用户注册后注册钱包
    @Insert("insert into user_purse values(null, ${userId}, 0, 0, '${opCode}', 0, 0, null)")
    int createUserPurse(UserPurse userPurse);

    // 根据用户编号查询钱包信息
    @Select("select availableBalance, freezeBalance, status, remark from user_purse where userId=${userId}")
    UserPurse getUserPurseByUserId(Long userId);

    // 根据用户编号获取用户操作码
    @Select("select opCode from user_purse where userId=${userId}")
    UserPurse getUserPurseOpCode(Long userId);

    // 修改钱包操作码
    @Update("update user_purse set opCode='${opCode}', errorNum=${errorNum} where userId=${userId}")
    int editUserPurseOpCode(UserPurse userPurse);

    // 修改冻结余额数据
    @Update("update user_purse set freezeBalance='${freezeBalance}' where userId=${userId}")
    int editUserPurseFreezeBalance(UserPurse userPurse);
}
